package socketVersion.Backend.Flights;

import java.util.LinkedList;

import socketVersion.GenericClient;
import socketVersion.Reply;
import socketVersion.Request;

public class FlightServerWrapper extends GenericClient implements FlightInterface{

	public FlightServerWrapper(String ip, int port) {
		super(ip, port);
	}

	@Override
	public boolean addFlight(int id, int flightNum, int flightSeats,
			int flightPrice) {
		return false;
	}

	@Override
	public boolean deleteFlight(int id, int flightNum) {
		return false;
	}

	@Override
	public int queryFlight(int id, int flightNumber) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int queryFlightPrice(int id, int flightNumber) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean reserveFlight(int id, int customer, int flightNumber) {
		LinkedList<Object> args = new LinkedList<Object>();
		args.add(id);
		args.add(customer);
		args.add(flightNumber);
		
		Request request = new Request("reserveFlight",args);
		Reply reply = sendRequest(request);
		if(reply.getStatus()==Reply.STATUS_SUCCESS){
			return ((Boolean)reply.getOutput().get(0)).booleanValue();
		}
		else{
			return false;
		}
	}

	@Override
	public boolean deleteReservation(int id, int customer) {
		LinkedList<Object> args = new LinkedList<Object>();
		args.add(id);
		args.add(customer);
		
		Request request = new Request("deleteReservation",args);
		Reply reply = sendRequest(request);
		if(reply.getStatus()==Reply.STATUS_SUCCESS){
			return ((Boolean)reply.getOutput().get(0)).booleanValue();
		}
		else{
			return false;
		}
	}

	@Override
	public int calculateBill(int id, int customer) {
		LinkedList<Object> args = new LinkedList<Object>();
		args.add(id);
		args.add(customer);
		
		Request request = new Request("calculateBill",args);
		Reply reply = sendRequest(request);
		if(reply.getStatus()==Reply.STATUS_SUCCESS){
			return ((Integer)reply.getOutput().get(0)).intValue();
		}
		else{
			return -1;
		}
	}

}
